package com.qianyue.责任链模式;

/**
 * 请假处理器
 *
 * @author qian yue
 * @version v1.0.0
 * @since 2025/2/9 19:39
 */
public abstract class Handler {
    protected final static int NUM_ONE = 1;
    protected final static int NUM_THREE = 3;
    protected final static int NUM_SEVEN = 7;

    private int numStart;
    private int numEnd;
    private Handler nextHandler;

    public Handler(int numStart) {
        this.numStart = numStart;
    }

    public Handler(int numEnd, int numStart) {
        this.numEnd = numEnd;
        this.numStart = numStart;
    }

    public void setNextHandler(Handler nextHandler) {
        this.nextHandler = nextHandler;
    }

    public void submit(LeaveRequest leaveRequest) {
        if (0 == this.numStart) {
            return;
        }
        //如果请假天数达到该领导者的处理要求
        if (leaveRequest.getNum() >= numStart) {
            handleLeave(leaveRequest);
            //如果还有上级 并且请假天数超过了当前领导的处理范围
            if (nextHandler != null && leaveRequest.getNum() > numEnd) {
                nextHandler.submit(leaveRequest);
            }else {
                System.out.println("流程结束");
            }
        }
    }

    protected abstract void handleLeave(LeaveRequest leaveRequest);
}
